home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / lo-utils.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  1KB  |  61 lines

  1. // utils.cc
  2. /*
  3.  
  4. Copyright (C) 1996 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22. */
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27.  
  28. #include <climits>
  29.  
  30. #include "lo-mappers.h"
  31. #include "lo-utils.h"
  32.  
  33. // Convert X to the nearest integer value.  Should not pass NaN to
  34. // this function.
  35.  
  36. int
  37. NINT (double x)
  38. {
  39.   if (x > INT_MAX)
  40.     return INT_MAX;
  41.   else if (x < INT_MIN)
  42.     return INT_MIN;
  43.   else
  44.     return (x > 0) ? ((int) (x + 0.5)) : ((int) (x - 0.5));
  45. }
  46.  
  47. double
  48. D_NINT (double x)
  49. {
  50.   if (xisinf (x) || xisnan (x))
  51.     return x;
  52.   else
  53.     return floor (x + 0.5);
  54. }
  55.  
  56. /*
  57. ;;; Local Variables: ***
  58. ;;; mode: C++ ***
  59. ;;; End: ***
  60. */
  61.